package com.nickstumpos.android.GmailWidgetPlus.gmailObserver;

import java.util.Calendar;

import android.database.ContentObserver;
import android.os.Handler;

public class GmailObserver extends ContentObserver {

	private IObserveChangeListener	listener	= null;
	private Long					lastSeen	= 0L;

	public GmailObserver(final Handler handler) {

		super(handler);
	}

	@Override
	public void onChange(final boolean selfChange) {

		if ((this.listener != null) && (Calendar.getInstance()
				.getTimeInMillis() - this.lastSeen > 100L)) {
			this.listener.onChange();
		}
		this.lastSeen = Calendar.getInstance().getTimeInMillis();
	}

	/**
	 * @param listener
	 *            the listener to set
	 */
	public void setListener(final IObserveChangeListener listener) {

		this.listener = listener;
	}
}
